{% block correlations_block %}
<!-- BEGIN /ionosphere/fp_veiw=true block -->

{% if print_debug == 'True' %}
<code> DEBUG </code> :: /ionosphere correlations_block</br>
  {% if requested_timestamp %}
<code> requested_timestamp </code>: {{ requested_timestamp }}<br>
  {% else %}
<code> requested_timestamp </code>: NOT FOUND<br>
  {% endif %}
{% endif %}

{% if display_message %}
<code> ERROR </code></br>
<code> message </code>: {{ display_message }}<br>
{% endif %}

  {% if correlations != False %}
	  <h4><span class="logo"><span class="sky">Existing ::</span> <span class="re">cross correlations ::</span></span> {{ correlations|length }} (listed strongest 1.0000 to weakest 0.0)</h4>
<!-- # @added 20180723 - Feature #2470: Correlations Graphite graph links
#                        Branch #2270: luminosity
# Added Graphite graph links to Correlations block
-->
	  <div class="alert alert-warning">
      These are the correlations from the entire metric population that fall within settings.LUMINOL_CROSS_CORRELATION_THRESHOLD,
      they are not necessarily all <strong>contextually related</strong>, but the <strong>contextually related</strong>
      correlations may be listed here if there are any.  These are simply the <strong>numeric</strong> correlations it is currently
      up to the operator to review them.  As it is assumed that the operator may know which metrics are likely to correlate
      with this anomaly on {{ for_metric }}, until such a time as Skyline can, something on the roadmap.
	  </div>
		  <table class="table table-hover">
		    <thead>
		      <tr>
		        <th>metric</th>
		        <th>coefficient</th>
		        <th>shifted</th>
		        <th>shifted_coefficient</th>
		      </tr>
		    </thead>
		    <tbody>
    {% for correlation_item in correlations_with_graph_links %}
		      <tr>
<!-- # @modified 20180723 - Feature #2470: Correlations Graphite graph links
#                           Branch #2270: luminosity
# Added Graphite graph links to the Correlations block in training_data and
# features_profile pages
		        <td>{{ correlation_item[0] }}</td>-->
		        <td><a target='_blank' href="{{ correlation_item[4] }}">{{ correlation_item[0] }}</a></td>
 		        <td>{{ correlation_item[1] }}</td>
		        <td>{{ correlation_item[2] }}</td>
		        <td>{{ correlation_item[3] }}</td>
		      </tr>
    {% endfor %}
		    </tbody>
		  </table>
  {% else %}
	  <h4><span class="logo"><span class="sky">Existing ::</span> <span class="re">correlations ::</span></span> None</h4>
  {% endif %}

<!-- # @added 20200113 - Feature #3390: luminosity related anomalies
#                        Branch #2270: luminosity
# Added Graphite graph links to Related block
-->
  {% if related != False %}
	  <h4><span class="logo"><span class="sky">Existing ::</span> <span class="re">possible related anomalies ::</span></span> {{ related|length }}</h4>
	  <div class="alert alert-warning">
      These are the time related anomalies from the entire metric population that fall within 2 minutes either side of the anomaly,
      they are not necessarily all <strong>related</strong>, but anomalies that occurred in the same time frame
      are listed here.  It is currently up to the operator to review them.  As it is assumed that the operator may
      know which metrics are likely to be related with this anomaly on {{ for_metric }}.
	  </div>
		  <table class="table table-hover">
		    <thead>
		      <tr>
		        <th>anomaly_id</th>
		        <th>metric</th>
		        <th>timestamp</th>
		        <th>full_duration</th>
		        <th>date</th>
		      </tr>
		    </thead>
		    <tbody>
    {% for related_item in related_with_graph_links %}
		      <tr>
		        <td><a target='_blank' href="{{ related_item[5] }}">{{ related_item[0] }}</a></td>
 		        <td>{{ related_item[1] }}</td>
		        <td>{{ related_item[2] }}</td>
		        <td>{{ related_item[3] }}</td>
		        <td>{{ related_item[4] }}</td>
		      </tr>
    {% endfor %}
		    </tbody>
		  </table>
  {% else %}
	  <h4><span class="logo"><span class="sky">Existing ::</span> <span class="re">related anomalies ::</span></span> None</h4>
  {% endif %}

  {% if related_matches != False %}
	  <h4><span class="logo"><span class="sky">Existing ::</span> <span class="re">possible related matches ::</span></span> {{ related_matches|length }}</h4>
	  <div class="alert alert-warning">
      These are the time related matches from the Ionosphere metric population that fall within 2 minutes either side of the anomaly,
      they are not necessarily all <strong>related</strong>, but the matches occurred in the same time frame
      are listed here.  It is currently up to the operator to review them.  As it is assumed that the operator may
      know which metrics are likely to be related with this anomaly on {{ for_metric }}.
	  </div>
		  <table class="table table-hover">
				<thead>
					<tr>
<!-- [human_date, match_id, matched_by, fp_id, layer_id, metric, uri_to_matched_page, validated, timestamp] -->
            <th>match id</th>
            <th>metric</th>
            <th>matched by</th>
            <th>fp_id</th>
            <th>layer_id</th>
            <th>date</th>
					</tr>
				</thead>
				<tbody>
    {% for item in related_matches %}
          <tr>
      {% if 'features profile' in item[2]  %}
        {% if item[7] == 2 %}
            <td onclick="window.location='?fp_view=true&fp_id={{ item[3] }}&metric={{ item[5] }}'">
              <a href="?fp_view=true&fp_id={{ item[3] }}&metric={{ item[5] }}&matched_fp_id={{ item[1] }}&match_validation=2">{{ item[1] }}</a>
            </td>
        {% elif item[7] == 1 %}
            <td onclick="window.location='?fp_view=true&fp_id={{ item[3] }}&metric={{ item[5] }}'">
              <a href="?fp_view=true&fp_id={{ item[3] }}&metric={{ item[5] }}&matched_fp_id={{ item[1] }}&match_validation=1">{{ item[1] }}</a>
            </td>
        {% else %}
            <td onclick="window.location='?fp_view=true&fp_id={{ item[3] }}&metric={{ item[5] }}'">
              <a href="?fp_view=true&fp_id={{ item[3] }}&metric={{ item[5] }}&matched_fp_id={{ item[1] }}">{{ item[1] }}</a>
            </td>
        {% endif %}

            <td>{{ item[5] }}</td>

        {% if 'echo' in item[2]  %}
          {% if 'minmax' in item[2]  %}
            <td><span class="logo"><span class="sky">features profile - minmax <span class="re">echo</span></span></td>
          {% else %}
            <td><span class="logo"><span class="sky">features profile <span class="re">echo</span></span></td>
          {% endif %}
        {% else %}
            <td><span class="logo"><span class="sky">{{ item[2] }}</span></span></td>
        {% endif %}
      {% else %}
        {% if item[7] == 2 %}
            <td onclick="window.location='?fp_view=true&fp_id={{ item[3] }}&metric={{ item[5] }}'">
              <a href="?fp_view=true&fp_id={{ item[3] }}&metric={{ item[5] }}&matched_layer_id={{ item[1] }}&match_validation=2">{{ item[1] }}</a>
            </td>
        {% elif item[7] == 1 %}
            <td onclick="window.location='?fp_view=true&fp_id={{ item[3] }}&metric={{ item[5] }}'">
              <a href="?fp_view=true&fp_id={{ item[3] }}&metric={{ item[5] }}&matched_layer_id={{ item[1] }}&match_validation=1">{{ item[1] }}</a>
            </td>
        {% else %}
            <td onclick="window.location='?fp_view=true&fp_id={{ item[3] }}&metric={{ item[5] }}'">
              <a href="?fp_view=true&fp_id={{ item[3] }}&metric={{ item[5] }}&matched_layer_id={{ item[1] }}">{{ item[1] }}</a>
            </td>
        {% endif %}
            <td>{{ item[5] }}</td>
            <td><span class="logo"><span class="re">{{ item[2] }}</span></span></td>
      {% endif %}

            <td onclick="window.location='?fp_view=true&fp_id={{ item[3] }}&metric={{ item[5] }}'">
              <a href="?fp_view=true&fp_id={{ item[3] }}&metric={{ item[5] }}">{{ item[3] }}</a>
            </td>

      {% if item[4] == 'None' %}
            <td>{{ item[4] }}</td>
      {% else %}
            <td onclick="window.location='?fp_view=true&fp_id={{ item[3] }}&metric={{ item[5] }}'">
              <a href="?fp_view=true&fp_id={{ item[3] }}&metric={{ item[5] }}">{{ item[4] }}</a>
            </td>
      {% endif %}

            <td>{{ item[0] }}</td>
          </tr>
    {% endfor %}
				</tbody>
			</table>

  {% else %}
	  <h4><span class="logo"><span class="sky">Existing ::</span> <span class="re">possible related matches ::</span></span> None</h4>
  {% endif %}


{% endblock %}
